import { _decorator, Component, Node } from 'cc';
import { playerState } from './playerState';
import { ENTITY_STATE_ENUM } from '../../Enum';
const { ccclass, property } = _decorator;

@ccclass('GroundState')
export class GroundState extends playerState {
    onEnter(): void {
        super.onEnter();
        this.fsm.setGravityScale(this.fsm.player.data.gravityScale);
    }
    update(deltaTime: number): void {
        this.run(1)
        
        if(this.fsm.lastPressedJumpTime > 0 && this.fsm.lastOnGroundTime > 0){
            this.fsm.transit(ENTITY_STATE_ENUM.JUMP)
        }
        if(this.rb.linearVelocity.y < -0.05) {
            this.fsm.transit(ENTITY_STATE_ENUM.FALL) 
        }
        super.update(deltaTime);
    }
    onExit(): void {
        super.onExit(); 
    }
}


